<template>
  <div class="content">
    <el-container>
      <el-header class="el-header">
        <div class="el-header-left">
          <img src="../assets/img/head.jpeg" />
          <div>俊哥哥的管理系统</div>
        </div>
        <div class="el-header-right">
          <img src="../assets/img/logout.jpeg" @click="logout" />
        </div>
      </el-header>
      <el-container class="el-container">
        <el-aside class="el-aside" :width="isCollapse ? '64px' : '200px'">
          <div class="toggle-button" @click="toggleCollapse">|||</div>
          <el-menu
            @open="handleOpen"
            @close="handleClose"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#ffd04b"
            unique-opened
            :collapse="isCollapse"
            :collapse-transition="false"
          >
            <!-- 一级菜单 -->
            <el-submenu
              :index="menu.path"
              v-for="menu in menuList"
              :key="menu.path"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ menu.authName }}</span>
              </template>

              <!-- 二级菜单 -->
              <div v-if="menu.children && menu.children.length > 0">
                <el-menu-item
                  :index="children.path"
                  v-for="children in menu.children"
                  :key="children.path"
                >
                  <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>{{ children.authName }}</span>
                  </template>
                </el-menu-item>
              </div>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main class="el-main">Main</el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { GetMenuList } from '../request/api.js'
export default {
  name: 'home',
  mounted () {
    this.getMenuList()
  },
  data: () => {
    return {
      isCollapse: false,
      menuList: []
    }
  },
  methods: {
    logout () {
      sessionStorage.clear()
      this.$router.push('/login')
    },
    handleOpen (key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath);
    },
    getMenuList () {
      GetMenuList().then(res => {
        if (res.meta.status === 200) {
          this.menuList = res.data
        }
        console.log(res)
      })
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    }

  }
}
</script>

<style lang="scss" scoped>
.content {
  height: 100%;
  .el-header {
    display: flex;
    justify-content: space-between;
    background: #666;
    .el-header-left {
      display: flex;
      // justify-content: space-between;
      img {
        width: 60px;
        height: 60px;
      }
      div {
        display: flex;
        align-items: center;
        font-size: 30px;
        padding-left: 20px;
      }
    }
    .el-header-right {
      img {
        width: 50px;
        height: 50px;
      }
    }
  }

  .el-container {
    height: 100%;
    // background: #ffffff;

    .el-aside {
      height: 100%;
      background: #333744;
      .el-menu {
        border-right: none;
      }

      .toggle-button {
        background: #4a5064;
        text-align: center;
        font-size: 20px;
        line-height: 40px;
        letter-spacing: 0.2em;
      }
    }
  }
}
</style>
